<?php
defined('IN_IA') or exit('Access Denied');

global $_W, $_GPC;
$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
//通知列表页
if ($op == 'display') {

    $pindex = max(1, intval($_GPC['page']));
    $psize = 10;
    $condition = " uniacid = '{$_W['uniacid']}'";
    $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('aide_activity_remind') . " WHERE $condition");
    $remind=pdo_fetchall("SELECT id,title,aid FROM " . tablename('aide_activity_remind') . " WHERE uniacid='{$_W['uniacid']}' ORDER BY  id ASC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
    $activity=pdo_fetchall("SELECT id,title FROM " . tablename('aide_activity') . " WHERE uniacid='{$_W['uniacid']}' ORDER BY  id ASC");
    foreach ($activity as $value){
        $activity[$value['id']]=$value;
    }
    //记录总数
    $pager = pagination($total, $pindex, $psize);
    include aide_template ('remind');
    exit;
}

if ($op == 'post') {
    $remindid = intval($_GPC['remindid']);
    $remind=pdo_fetchall("SELECT * FROM " . tablename('aide_activity_remind') . " WHERE id=$remindid ORDER BY  id ASC LIMIT 1");
    $activity=pdo_fetchall("SELECT * FROM " . tablename('aide_activity') . " WHERE uniacid='{$_W['uniacid']}' ORDER BY id ASC");
    $remind=$remind[0];
    $time=date('Y-m-d H:i:s');
    if (checksubmit('submit')) {
        $form = $_GPC['remind'];
        $data['title'] = $form['title'];
        $data['uniacid'] = $_W['uniacid'];
        $data['image'] = $form['image'];
        $data['intro'] = $form['intro'];
        $data['fans_group'] = $form['fans_group'];
        $data['status'] = $form['status'];
        $data['aid'] = $form['aid'];
        $data['updated_at'] = $time;
        if (!empty($remindid)) {
            pdo_update ('aide_activity_remind', $data, array ('id' => $remindid));
        } else {
            $data['created_at'] = $time;
            pdo_insert ('aide_activity_remind', $data);
            $activityid = pdo_insertid();
        }
        message ('更新成功！', web_url('remind/remind/display'), 'success');
    }
    include aide_template ('remind');
    exit;
}

if ($op == 'delete') {
    $remindid = intval($_GPC['remindid']);
    pdo_delete ('aide_activity_remind', array ('id' => $remindid));
    die(json_encode(array("errno" => 0,'message'=>'删除成功')));
    exit;
}
